package ${package.Controller};
<#assign camelName = table.serviceName?uncap_first/>
import com.longcai.cm.base.aop.Log;
import com.longcai.cm.base.bean.PageVo;
import com.longcai.cm.base.bean.Pageable;
import com.longcai.cm.bean.R;
import com.longcai.cm.common.utils.RequestUtil;
import com.longcai.cm.common.utils.StringUtil;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
* @author ${author}
* @date ${date}
*/
@RestController
@RequestMapping("/${entity}")
public class ${table.controllerName} {

private final ${table.serviceName} ${camelName};

public ${table.controllerName}(${table.serviceName} ${camelName}) {
this.${camelName} = ${camelName};
}

@RequestMapping("/getList")
public R
<PageVo<${entity}>> getList(HttpServletRequest request) {
Pageable pageInfo = RequestUtil.getPageable(request);
PageVo<${entity}> result = ${camelName}.getPageBean(pageInfo, ${entity}.class);
return R.success(result);
}

/**
* @param vo 插入实体
*
* @return R
*/
@Log
@RequestMapping("/save")
public R
<String> save(${entity} vo) {
    if (StringUtils.isNotBlank(vo.getId())) {
    boolean success = ${camelName}.updateById(vo);
    return success ? R.success() : R.error();
    } else {
    final String uuid = StringUtil.getUuid();
    vo.setId(uuid);
    boolean success = ${camelName}.save(vo);
    return success ? R.success() : R.error();
    }
    }

    /**
    * @param vo 修改实体
    * @param request id
    *
    * @return R
    */
    @Log
    @RequestMapping("/edit")
    public R
    <String> edit(${entity} vo, HttpServletRequest request) {
        String id = request.getParameter("id");
        if (StringUtils.isNotBlank(id)) {
        boolean success = ${camelName}.updateById(vo);
        return success ? R.success() : R.error();
        } else {
        return R.error("id不能为空");
        }
        }

        /**
        * @param id 主键
        * @return R
        */
        @Log
        @RequestMapping("/delete/{id}")
        public R
        <String> deleteByPrimaryKey(@PathVariable("id") Integer id) {
            final boolean success = ${camelName}.removeById(id);
            return success ? R.success() : R.error();
            }

            /**
            * 【API】---- 删除多个数据
            *
            * @return R
            */
            @Log
            @RequestMapping("/delete")
            public R
            <String> delete(String ids) {
                String[] idStrings = ids.split(",");
                for (String idString : idStrings) {
                final boolean success = ${camelName}.removeById(idString);
                if (!success) {
                return R.error();
                }
                }
                return R.success();
                }
                }